﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

namespace SharpSNS
{
    /// <summary>
    /// Base class encapsulating the response from an API call
    /// </summary>
    public abstract class ApiResponse
    {
        private string _StatusText;
        /// <summary>
        /// Status text returned by the server
        /// </summary>
        public string StatusText
        {
            get { return _StatusText; }
        }

        private ApiResponseCode _ResponseCode;
        /// <summary>
        /// ApiResponseCode representing the status
        /// </summary>
        public ApiResponseCode ResponseCode
        {
            get { return _ResponseCode; }
        }

        private ApiStatusDetailCode _StatusDetailCode;
        /// <summary>
        /// ApiStatusDetailCode representing the status detail code
        /// </summary>
        public ApiStatusDetailCode StatusDetailCode
        {
            get { return _StatusDetailCode; }
        }

        /// <summary>
        /// Initializes the ApiResponse given the specified response data XML node
        /// </summary>
        /// <param name="respNode">Response data XML node</param>
        public ApiResponse(XmlNode respNode)
        {
            int statusCode = Convert.ToInt32(respNode["statusCode"].InnerText);
            _ResponseCode = (ApiResponseCode)statusCode;
            _StatusText = respNode["statusText"].InnerText;
            if (respNode["statusDetailCode"] != null)
                _StatusDetailCode = (ApiStatusDetailCode)int.Parse(respNode["statusDetailCode"].InnerText);
            else
                _StatusDetailCode = ApiStatusDetailCode.UnknownOrNone;
        }
    }
}
